<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>客户编辑</title>
[#include "../../include/main.ftl"]
[#include "/include/popdialog.ftl"]
	<style>
    	
    </style>
    <script>
        var rp = function refreshPage(data) {
            if (data != null) {
                $('#custSn').val(data.sn);
                $('#name').html(data.name);
                $('#custType').val(data.custType);
                $('#custTypeName').html(data.custTypeName);
                $('#IDCard').html(data.IDCard);
                $('#IDAddress').html(data.IDAddress);
                $('#compAddress').html(data.compAddress);
                $('#custLink').attr("href", "/Ins/customer/edit/" + data.sn);
				initCustomerCars(data.sn);
				initDriver();
            }
        };
		
		function initCustomerCars(sn) {
		    $.get('/Ins/Customer/getCars/' + sn, null,
            function(data){
                var tbodyCar = "";
                $.each(data, function(i, val){
                    tbodyCar += "<tr>"+
                                "<td><input type=\"radio\" name=\"custCarSn\" id=\"custCarSn_" + val.sn +"\" value=\"" + val.sn +"\">"+
                                    val.carNo + "</td>"+
                                "<td>"+ val.brand + val.brandKind +"</td>"+
								  "<td>"+ val.eno +"</td>"+
								   "<td>"+ val.vin +"</td>"+
								    "<td>"+ val.regDate +"</td>"+
                                "<td>"+ val.maxPerson +"</td>"+
                                "<td>"+val.cardDate+"</td>"+
								"<td>"+val.maWeight +'/'+val.totalWeight +"</td>"+
                            "</tr>" ;
							  
                });
                $('#cars').html(tbodyCar);
            },"json")
		}
        function initDriver() {
            if ($('#driverLimit').attr('checked') && $('#custSn').val() != '') {
                $.get('/Ins/Customer/getDrivers/' + $('#custSn').val(), null,
                function(data){
                    var tbodyDriver = "";
                    $.each(data, function(i, val){
                        tbodyDriver += "<tr>"+
                                    "<td><input type=\"checkbox\" name=\"custDriverSn\" id=\"custDriverSn_" + val.sn +"\" value=\""+ val.sn +"\">"+val.name + "</td>"+ "<td>"+ val.sex +"</td>"+
									
                                    "<td>"+ val.cardNo +"</td>"+
                                    "<td>"+ val.quasiDriving +"</td>"+
                                    "<td>"+ val.firstCardDate +"</td>"+
                                "</tr>" ;
                    });
                    $('#drivers').html(tbodyDriver);
                },"json");
                $('#div_drivers').show();
            } else {
                $('#div_drivers').hide();
            }
        }
		
        function selectUser() {
            popDialog("selectUser", "选择客户",
                    "/Ins/customer/select",
                    rp, 600, 600);
        }

        
		
		function setInsBeginDate(){
			$('#insBeginDate').val($('#lastInsEndDate').val());
			if ($('#lastInsEndDateTime').val() == '24') {
				$('#insBeginDateTime').val('0');
			} else {
				$('#insBeginDateTime').val(parseInt($('#lastInsEndDateTime').val())+1);
			}
			setInsEndDate();
		}
		
		function setInsEndDate(){
			var d = new Date($('#insBeginDate').val().replace('-', '/'));
			d.setFullYear(d.getFullYear()+1);
			d.setDate(d.getDate()-1);
			$('#insEndDate').val(d.format('yyyy-MM-dd'));
			if ($('#insBeginDateTime').val() == '0') {
				$('#insEndDateTime').val('24');
			} else {
				$('#insEndDateTime').val(parseInt($('#insBeginDateTime').val())-1);
			}
		}
		
		function calcTotalFee() {
            var tf1 = 0;
			var tf2 = 0;
			var tf3 = 0;
            $.each($('input[name*="premium"]'), function (i, val) {
                var feeid = val.id.substr(val.id.indexOf('_')+1);
                if ($('#fee_'+feeid).attr('checked')) {
                    if (val.value !=null && val.value!="" && !isNaN(val.value) && val.name.indexOf('1_') > -1 ) {
                        tf1 += parseFloat(val.value);
                    } else if (val.value !=null && val.value!="" && !isNaN(val.value) && val.name.indexOf('2_') > -1 ) {
                        tf2 += parseFloat(val.value);
                    } else if (val.value !=null && val.value!="" && !isNaN(val.value) && val.name.indexOf('3_') > -1 ) {
                        tf3 += parseFloat(val.value);
                    } 
                }
            });
			if (!isNaN(tf1)) $('#totalFee1').html(tf1);
			else $('#totalFee1').html('0');
			if (!isNaN(tf2)) $('#totalFee2').html(tf2);
			else $('#totalFee2').html('0');
			if (!isNaN(tf3)) $('#totalFee3').html(tf3);
			else $('#totalFee3').html('0');
			
			$('#totalFeeAll1').html(parseFloat($('#totalFee1').html())+parseFloat($('#jq').val())+parseFloat($('#cc').val()));
			$('#totalFeeAll2').html(parseFloat($('#totalFee2').html())+parseFloat($('#jq').val())+parseFloat($('#cc').val()));
			$('#totalFeeAll3').html(parseFloat($('#totalFee3').html())+parseFloat($('#jq').val())+parseFloat($('#cc').val()));
        }
		
		function calcTotalFeeFull() {
			var totalFeeFull1 = parseFloat($('#totalFee1').html())/parseFloat($('#discount1').val())*10;
			if (!isNaN(totalFeeFull1)) $('#totalFeeFull1').html(totalFeeFull1);
			else $('#totalFeeFull1').html('0');
			
			var totalFeeFull2 = parseFloat($('#totalFee2').html())/parseFloat($('#discount2').val())*10;
			if (!isNaN(totalFeeFull2)) $('#totalFeeFull2').html(totalFeeFull2);
			else $('#totalFeeFull2').html('0');
			
			var totalFeeFull3 = parseFloat($('#totalFee3').html())/parseFloat($('#discount3').val())*10;
			if (!isNaN(totalFeeFull3)) $('#totalFeeFull3').html(totalFeeFull3);
			else $('#totalFeeFull3').html('0');
        }
    </script>
</head>
<body>
<div class="ui-widget page">
[#include '../../top.ftl']

    <div class="content">
    [#include '../../leftNav.ftl']
        <div style="width:845px;float: left;padding-left: 5px">
            <div class="ui-widget-content ui-corner-all" style="min-height: 600px;">
                <form name="mainForm" method="post" action="/Ins/quote/save">
                <INPUT TYPE="hidden" NAME="sn" VALUE="${obj.QuoteObj.sn?default('')}">
                 <INPUT TYPE="hidden" NAME="createUser" VALUE="${obj.QuoteObj.createUser?default('')}">
                  <INPUT TYPE="hidden" NAME="createTime" VALUE="${(obj.QuoteObj.createTime?string('yyyy-MM-dd'))?default('')}">
                <INPUT TYPE="hidden" NAME="custSn" id="custSn" VALUE="${obj.QuoteObj.custSn?default('')}">
                    【<a href="/Ins/quote/list">返回报价单查询</a>】

                    <div id="contract_base">
                        <p>【被保险人资料】【<a href="javaScript:selectUser();">选择客户</a>】 </p>
                        <table width="100%" border="0" cellspacing="4">
                            <tr>
                                <td bgcolor="#CCCCCC">客户名称</td>
                              <td><span id="name">${(obj.CustomerObj.name)!''}</span></td>
                              <td bgcolor="#CCCCCC">身份证号 </td>
                              <td><span id="IDCard">${(obj.CustomerObj.IDCard)!''}</span></td>
                            </tr>
                            <tr>
                                <td bgcolor="#CCCCCC">身份证地址</td>
                              <td colspan="3"><span id="IDAddress">${(obj.CustomerObj.IDAddress)!''}</span></td>
                            </tr>
                            <tr>
                                <td bgcolor="#CCCCCC">单位地址</td>
                              <td colspan="3"><span id="compAddress">${(obj.CustomerObj.compAddress)!''}</span></td>
                            </tr>
                        </table>
                        <table width="100%" border="0" cellpadding="0" cellspacing="4">
                            <tr>
                                <td colspan="8" bgcolor="#CCCCCC">投保车辆</td>
                            </tr>
                            <tr>
                                <td>车牌号</td>
                                <td>品牌型号</td>
                                <td>发动机号</td>
                                <td>识别号</td>
                                <td>初登日期</td>
                                <td>座位数</td>
                                <td>发证日期</td>
                                <td>整备/总质量</td>
                            </tr>
                            <tbody id="cars">
                            [#list obj.CustomerCars?default([]) as car]
                            <tr>
                                <td><input type="radio" name="custCarSn" id="custCarSn_${car.sn}" value="${car.sn}">
                                    ${car.carNo!""}
                                </td>
                                <td> ${car.brand!""}
                                ${car.brandKind!""}</td>
                                <td>${car.eno!""}</td>
                                <td>${car.vin!""}</td>
                                <td>${(car.regDate?string('yyyy-MM-dd'))?default('')}</td>
                                <td>${car.maxPerson?default('')}</td>
                                <td>${(car.cardDate?string('yyyy-MM-dd'))?default('')}</td>
                                <td>${(car.maWeight?string(''))?default('')}/${(car.totalWeight?string(''))?default('')}</td>
                            </tr>
                            [/#list]
                            </tbody>
                            <script>$("#custCarSn_${(obj.QuoteObj.custCarSn)!''}").attr("checked",'true');</script>
                        </table>
                        <p>
<label>
                                <input type="checkbox" name="provinceLimit"  id="provinceLimit" value="1">
[#if obj.QuoteObj.provinceLimit?default(0) == 1 ]<script>$("#provinceLimit").attr('checked', 'true');</script>[/#if]
                                限省内</label>
                            <label>
                                <input type="checkbox" name="driverLimit" value="1" id="driverLimit" onclick="initDriver();">
[#if obj.QuoteObj.driverLimit?default(0) == 1 ]<script>$("#driverLimit").attr('checked', 'true');</script>[/#if]
                                限驾驶员<br>
                            </label>
                        </p>
                        <div id = "div_drivers">
                        <table width="100%" border="0" cellpadding="0" cellspacing="4">
                            <tr>
                                <td colspan="5" bgcolor="#CCCCCC">驾驶员信息</td>
                            </tr>
                            <tr>
                                <td>姓名</td>
                                <td>性别</td>
                                <td>驾驶证号</td>
                                <td>准驾车型</td>
                                <td>初次领证</td>
                            </tr>
                            <tbody id="drivers">
                            [#list obj.CustomerDrivers?default([]) as driver]
                            <tr>
                                <td><input type="checkbox" name="custDriverSn" id="custDriverSn_${driver.sn}" value="${driver.sn}">
                                ${driver.name}</td>
                                <td>${driver.sex}</td>
                                <td>${driver.cardNo}</td>
                                <td>${(driver.quasiDriving)?default('')}</td>
                                <td>${(driver.firstCardDate?string('yyyy-MM-dd'))?default('')}</td>
                            </tr>
                            [/#list]

                            </tbody>
                        </table>
    </div>
                            <script>
                        [#if obj.QuoteObj.driverLimit?default(0) == 0 ]
						
							$('#div_drivers').hide();
						[#else]
                        	[#list obj.QuoteDrivers?default([]) as d]
							$('#custDriverSn_${d.custDriverSn}').attr('checked', 'true');
							[/#list]
                        
                        [/#if]
							</script>
                        
                      <p>去年投保公司
						<select name="lastComp" id="lastComp">
                                [#list obj.insCompList?default([]) as ic]
                            
                                <option value="${ic.sn}">
                                  ${ic.name}
                                </option>
                                [/#list]
                        </select>
						<script>$("#lastComp").val("${(obj.QuoteObj.lastComp)?default('')}");</script>
                      去年投保止日期
                        <input type="text"  size="20" id="lastInsEndDate" name="lastInsEndDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" ><script>$("#lastInsEndDate").val("${(obj.QuoteObj.lastInsEndDate?string('yyyy-MM-dd'))?default('')}");</script>
                        <select name="lastInsEndDateTime" id="lastInsEndDateTime">
                          <option value="0">零时</option>
                          <option value="1">一时</option>
                          <option value="2">二时</option>
                          <option value="3">三时</option>
                          <option value="4">四时</option>
                          <option value="5">五时</option>
                          <option value="6">六时</option>
                          <option value="7">七时</option>
                          <option value="8">八时</option>
                          <option value="9">九时</option>
                          <option value="10">十时</option>
                          <option value="11">十一时</option>
                          <option value="12">十二时</option>
                          <option value="13">十三时</option>
                          <option value="14">十四时</option>
                          <option value="15">十五时</option>
                          <option value="16">十六时</option>
                          <option value="17">十七时</option>
                          <option value="18">十八时</option>
                          <option value="19">十九时</option>
                          <option value="20">二十时</option>
                          <option value="21">二十一时</option>
                          <option value="22">二十二时</option>
                          <option value="23">二十三时</option>
                          <option value="24" selected>二十四时</option>
                        </select><script>$("#lastInsEndDateTime").val("${obj.QuoteObj.lastInsEndDateTime?default('24')}");</script>
                        <input type="button" name="button" id="button" value="按此时间续保" onClick="setInsBeginDate()">
                      </p>
                      <p>保险有效起止日期
                              <input type="text"  size="14" id="insBeginDate" name="insBeginDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >

<script>$("#insBeginDate").val("${(obj.QuoteObj.insBeginDate?string('yyyy-MM-dd'))?default('')}");</script>
<select name="insBeginDateTime" id="insBeginDateTime" onChange="setInsEndDate()">
  <option value="0" selected>零时</option>
  <option value="1">一时</option>
  <option value="2">二时</option>
  <option value="3">三时</option>
  <option value="4">四时</option>
  <option value="5">五时</option>
  <option value="6">六时</option>
  <option value="7">七时</option>
  <option value="8">八时</option>
  <option value="9">九时</option>
  <option value="10">十时</option>
  <option value="11">十一时</option>
  <option value="12">十二时</option>
  <option value="13">十三时</option>
  <option value="14">十四时</option>
  <option value="15">十五时</option>
  <option value="16">十六时</option>
  <option value="17">十七时</option>
  <option value="18">十八时</option>
  <option value="19">十九时</option>
  <option value="20">二十时</option>
  <option value="21">二十一时</option>
  <option value="22">二十二时</option>
  <option value="23">二十三时</option>
  <option value="24">二十四时</option>
</select>
<script>$("#insBeginDateTime").val("${obj.QuoteObj.insBeginDateTime?default('0')}");</script> 至
                             <input type="text"  size="14" id="insEndDate" name="insEndDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >

<script>$("#insEndDate").val("${(obj.QuoteObj.insEndDate?string('yyyy-MM-dd'))?default('')}");</script>
    <select name="insEndDateTime" id="insEndDateTime">
      <option value="0">零时</option>
      <option value="1">一时</option>
      <option value="2">二时</option>
      <option value="3">三时</option>
      <option value="4">四时</option>
      <option value="5">五时</option>
      <option value="6">六时</option>
      <option value="7">七时</option>
      <option value="8">八时</option>
      <option value="9">九时</option>
      <option value="10">十时</option>
      <option value="11">十一时</option>
      <option value="12">十二时</option>
      <option value="13">十三时</option>
      <option value="14">十四时</option>
      <option value="15">十五时</option>
      <option value="16">十六时</option>
      <option value="17">十七时</option>
      <option value="18">十八时</option>
      <option value="19">十九时</option>
      <option value="20">二十时</option>
      <option value="21">二十一时</option>
      <option value="22">二十二时</option>
      <option value="23">二十三时</option>
      <option value="24" selected>二十四时</option>
    </select>
<script>$("#insEndDateTime").val("${obj.QuoteObj.insEndDateTime?default('24')}");</script>                      
                      </p>

                      <p><script>$("#insCompany").val("${(obj.QuoteObj.insCompany)?default('')}");</script>
                            报价日期
                            <input type="text"  size="20" id="quoteDate" name="quoteDate" class="validate-date-yyyy-MM-dd" onClick="popCalendar(this)" >

<script>$("#quoteDate").val("${(obj.QuoteObj.quoteDate?string('yyyy-MM-dd'))?default('')}");</script>
                        </p>
                      <table border="0" cellspacing="1" cellpadding="0">
                        <tr>
                                <td rowspan="2" bgcolor="#CCCCCC">商业险种</td>
                              <td rowspan="2" bgcolor="#CCCCCC">保额（元）</td>
                                <td colspan="3" bgcolor="#CCCCCC">保费（元）</td>
                            </tr>
                            <tr>
                              <td bgcolor="#CCCCCC"><select name="insCompany1" id="insCompany1" style="width:150px">
                                [#list obj.insCompList?default([]) as ic]
                            
                                <option value="${ic.sn}">
                                  ${ic.name}
                                </option>
                                [/#list]
                              </select></td>
                              <td bgcolor="#CCCCCC"><select name="insCompany2" id="insCompany2" style="width:150px">
                              	<option value="" selected></option>
                                [#list obj.insCompList?default([]) as ic]
                            
                                
                                <option value="${ic.sn}">
                                  ${ic.name}
                                </option>
                                [/#list]
                              </select></td>
                              <td bgcolor="#CCCCCC"><select name="insCompany3" id="insCompany3" style="width:150px">
                              <option value="" selected></option>
                                [#list obj.insCompList?default([]) as ic]

                                <option value="${ic.sn}">
                                  ${ic.name}
                                </option>
                                [/#list]
                              </select></td>
                            </tr>
                            [#list obj.feeList?default([]) as fee]
                            <tr>
                                <td><input type="checkbox" name="fee" value="${fee.sn}" id="fee_${fee.sn}" onChange="calcTotalFee();">
                                    ${fee.name}
                                </td>
                                <td>
                            <input type="text"  size="30" id="insured_${fee.sn}" name="insured_${fee.sn}"  ></td>
                                <td><input type="text"  size="20" id="premium1_${fee.sn}" name="premium1_${fee.sn}" onChange="calcTotalFee();"></td>
                                <td><input type="text"  size="20" id="premium2_${fee.sn}" name="premium2_${fee.sn}" onChange="calcTotalFee();"></td>
                                <td><input type="text"  size="20" id="premium3_${fee.sn}" name="premium3_${fee.sn}" onChange="calcTotalFee();"></td>
                            </tr>
                            [/#list]
                             <tr>
                                <td bgcolor="#99CC99">小计</td>
                                <td bgcolor="#99CC99">&nbsp;</td>
                                <td bgcolor="#99CC99"><span id="totalFee1"></span>
                                <input name="submit3" type="submit" value="转成保单" onClick="mainForm.action='/Ins/quote/convert/1';"></td>
                                <td bgcolor="#99CC99"><span id="totalFee2"></span><input name="submit3" type="submit" value="转成保单" onClick="mainForm.action='/Ins/quote/convert/2';"></td>
                                <td bgcolor="#99CC99"><span id="totalFee3"></span><input name="submit3" type="submit" value="转成保单" onClick="mainForm.action='/Ins/quote/convert/3';"></td>
                            </tr>
                            <tr>
                                <td>备注</td>
                                <td>&nbsp;</td>
                                <td>
                              <textarea name="insRemark1" id="insRemark1" cols="20" rows="5"></textarea></td>
                                <td><textarea name="insRemark2" id="insRemark2" cols="20" rows="5"></textarea></td>
                                <td><textarea name="insRemark3" id="insRemark3" cols="20" rows="5"></textarea></td>
                            </tr>
                            <tr>
                              <td>折扣</td>
                              <td>&nbsp;</td>
                              <td>
                              <input name="discount1" type="text" id="discount1" size="10" onChange="calcTotalFeeFull()"><span id="totalFeeFull1"></span></td>
                              <td><input name="discount2" type="text" id="discount2" size="10"  onChange="calcTotalFeeFull()"><span id="totalFeeFull2"></span></td>
                              <td><input name="discount3" type="text" id="discount3" size="10"  onChange="calcTotalFeeFull()"><span id="totalFeeFull3"></span></td>
                            </tr>
                                               
                          <tr>
                            <td bgcolor="#CCCCCC">交强车船</td>
                            <td bgcolor="#CCCCCC">保额（元）</td>
                            <td colspan="3" bgcolor="#CECFCE">金额</td>
                          </tr>



                          <tr>
                            <td>交强险</td>
                            <td><label for="jq"><a href="#">保额</a></label></td>
                            <td colspan="3" bgcolor="#FFFFFF"><input name="jq" type="text" id="jq" value="980"></td>
                          </tr>
                          <tr>
                            <td height="20">车船税</td>
                            <td><label for="cc"></label></td>
                            <td colspan="3" bgcolor="#FFFFFF"><input name="cc" type="text" id="cc" value="420"></td>
                          </tr>
                          <tr>
                            <td colspan="2" bgcolor="#CC9933">合计</td>
                            <td bgcolor="#CC9933"><span id="totalFeeAll1"></span></td>
                            <td bgcolor="#CC9933"><span id="totalFeeAll2"></span></td>
                            <td bgcolor="#CC9933"><span id="totalFeeAll3"></span></td>
                          </tr>
                        </table>
                         </p>

<script>
                        [#list obj.QuoteInsDetails?default([]) as i]
						[#if i.quoteOrder?default(0) > 0 ]
                        	$('#fee_${i.insKind}').attr('checked', 'true');
							if ($('#insured_${i.insKind}').val() == '') {
								$('#insured_${i.insKind}').val('${i.insured}');
							} else {
								if ($('#insured_${i.insKind}').val() != '${i.insured}')  
									$('#insured_${i.insKind}').val($('#insured_${i.insKind}').val()+'/${i.insured}');
							}
							
							$('#insCompany${i.quoteOrder?default(0)}').val('${i.insCompany!''}');
							$('#insRemark${i.quoteOrder?default(0)}').val('${i.insRemark!''}');
							$('#discount${i.quoteOrder?default(0)}').val('${i.discount!''}');
							$('#premium${i.quoteOrder?default(0)}_${i.insKind}').val('${i.premium}');
						[#else] 
							[#if i.insKind = 'jq']
							$('#jq').val('${i.premium}');
							[/#if]
							[#if i.insKind = 'cc']
							$('#cc').val('${i.premium}');
							[/#if]
						[/#if]
                        [/#list]
						calcTotalFee();
						calcTotalFeeFull();
						  </script>

                        <table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
                                <td colspan="4" bgcolor="#CCCCCC">备注</td>
                          </tr>
                            <tr>
                                <td colspan="4"><textarea name="quoteRemark" id="quoteRemark" cols="70" rows="5">${obj.QuoteObj.quoteRemark!''}</textarea></td>
                            </tr>
                        </table>
                      <table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
                                <td colspan="4" bgcolor="#CCCCCC">客户类别</td>
                            </tr>
                            <tr>
                                <td colspan="4">     
                                  <input type="radio" name="radio2" id="radio2" value="radio2">
                                金卡
                                <input type="radio" name="radio3" id="radio3" value="radio3">
                                白金卡
                                <input type="radio" name="radio" id="radio" value="radio">
                                  钻石卡
                              </td>
                            </tr>
                        </table>
                        <p>
                          <input name="submit" type="submit" value="保存" onClick="">
                        |
                        <input name="submit2" type="submit" value="提交报价" onClick="">
                        | <a href="/Ins/quote/del/${obj.QuoteObj.sn?default('')}" onClick="return confirm('确定删除?')">删除</a></p>

                        <p>
                    <label> </label>
                            <br>
                        </p>
                    </div>

                </form>
            </div>

        </div>
    </div>

[#include '../../bottom.ftl']
</div>
</body>
</html>